using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

/*	Should be attached to every alien GameObject
 *   - DOES have data structures for each chromosome
 *   - functions will be added to report the phenotypes of the Alien too
 * */

public class AlienGenome : MonoBehaviour {
	public readonly Chromosome Strength= new Chromosome(Chromosome.ChromosomeType.STRENGTH, 0,0);
	public readonly Chromosome Smarts= new Chromosome(Chromosome.ChromosomeType.SMARTS, 0,0);
	public readonly Chromosome Speed= new Chromosome(Chromosome.ChromosomeType.SPEED, 0,0);
	public readonly Chromosome Defense= new Chromosome(Chromosome.ChromosomeType.DEFENSE, 0,0);
	public readonly Chromosome Attack= new Chromosome(Chromosome.ChromosomeType.ATTACK, 0,0);
	public readonly List<GameObject> Phenotype= new List<GameObject>();

	public string 	AlienName;
	public int 		Generation=0;
	public int 		MatingPotential=3;
	public int 		Wins=0;
	public int		TotalFights=0;
	public Color	coat;
	public Material coatMaterial;

	// Use this for initialization
	void Awake () {
		coat= new Color(UnityEngine.Random.Range(0.0f, 256.0f)/255.0f, UnityEngine.Random.Range(0.0f, 256.0f)/255.0f, UnityEngine.Random.Range(0.0f, 256.0f)/255.0f);
		Material dupe= new Material(coatMaterial);
		dupe.name= "RandomMaterial";
		coatMaterial= dupe;
		coatMaterial.color= coat;
	}
	
	// Update is called once per frame
	void Update () {
	
	
	}
	
	public void lyse() {
		Destroy(this.gameObject);	
	}
	
	public Chromosome getChromosome(Chromosome.ChromosomeType type) {
		if(type	== Chromosome.ChromosomeType.ATTACK)
			return Attack;
		if(type	== Chromosome.ChromosomeType.DEFENSE)
			return Defense;
		if(type	== Chromosome.ChromosomeType.SMARTS)
			return Smarts;
		if(type	== Chromosome.ChromosomeType.SPEED)
			return Speed;
		if(type	== Chromosome.ChromosomeType.STRENGTH)
			return Strength;
		
		return null;
	}
	
	public string ToString() {
		return AlienName + ":\n" + 
			    Strength.ToString() + "\n" +
				Smarts.ToString() + "\n" +
				Speed.ToString() + "\n" +
				Defense.ToString() + "\n" +
				Attack.ToString() + "\n";
	}
	
	public void generatePhenotype() {
		Defense.GeneratePhenotype();
		Attack.GeneratePhenotype();
		Speed.GeneratePhenotype();
		Smarts.GeneratePhenotype();
		Strength.GeneratePhenotype();
	}
	

	
	public void duplicate(AlienGenome source) {
		Attack.duplicate(source.Attack);
		Defense.duplicate(source.Defense);
		Smarts.duplicate(source.Smarts);
		Speed.duplicate(source.Speed);
		Strength.duplicate(source.Strength);
		
		AlienName= source.AlienName;
		Generation= source.Generation;
		MatingPotential= source.MatingPotential;
		Wins= source.Wins;
		TotalFights= source.TotalFights;
	}
	
	public Material GetCoat() {
		Debug.Log(coatMaterial.name);
		return coatMaterial;
	}
}
